#External libraries imports
from pyparsing import col, lineno

class SourceException(Exception):
  def __init__(self, source, location, message):
    self.source = source
    self.location = location
    self.message = message
  def __str__(self):
    return ("(line: " + str(lineno(self.location, self.source)) +
            ", column: " + str(col(self.location, self.source)) +
            "): " + self.message)

class SyntacticException(SourceException):
  def __init__(self, source, line, message):
    super(SyntacticException, self).__init__(source, line, message)

class SemanticException(SourceException):
  def __init__(self, source, line, message):
    super(SemanticException, self).__init__(source, line, message)

class RedeclarationException(SemanticException):
  def __init__(self, source, line, name):
    super(RedeclarationException, self).__init__(source, line,
                                                "Redeclaration of " + name)

class RedefinitionException(SemanticException):
  def __init__(self, source, line, name):
    super(RedefinitionException, self).__init__(source, line,
                                                "Redefinition of " + name)

class UndefinedNameException(SemanticException):
  def __init__(self, source, line, name):
    super(UndefinedNameException, self).__init__(source, line,
                                                 name + " undefined")

class ValueTypeException(SemanticException):
  def __init__(self, source, line, expectedType):
    super(ValueTypeException, self).__init__(source, line,
                                                 expectedType + " expected")

class LabelsMismatchException(SemanticException):
  def __init__(self, source, line):
    super(LabelsMismatchException, self).__init__(source, line, "Cannot relabel process: labels mismatch")
